package com.lanhai.zhonglai.dispatch;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.stereotype.Service;

import com.lanhai.zhonglai.beans.StationBean;
import com.lanhai.zhonglai.interfaces.IAgv;
import com.lanhai.zhonglai.interfaces.IControlArea;
import com.lanhai.zhonglai.interfaces.IStation;
import com.lanhai.zhonglai.interfaces.IStationMount;
import com.lanhai.zhonglai.interfaces.IDot;
import com.lanhai.zhonglai.interfaces.IPower; 

@EnableAsync
@Service
public class DispatchHack {
	@Autowired
	IControlArea iControlArea;
	
	@Autowired
	IStation iStation;
	 
	 
	
	@Autowired
	IPower iPower;
	
	@Autowired
	IDot iDot;
	
	@Autowired
	IStationMount iStationMount;
		
	@Autowired
	IAgv iAgv;
	 
	
	@Async("agvExecutor") 
	public  void releaseControllerArea(long areaid) {
		//交管区解锁
		iControlArea.unlockArea(areaid );
	}
	
	@Async("agvExecutor") 
	public  void releaseStation(int dotno ) {
		//机台解锁
		iStation.unlockStationByHacker(dotno); 
	}
	
	
	
	/**
	 * 重置交管区基础数据
	 * @param areaid
	 */
	@Async("agvExecutor") 
	public  void reloadControllerArea( ) {
		//交管区解锁
		iControlArea.init();
	}
	
	/**
	 * 重置点位数据
	 * @param areaid
	 */
	@Async("agvExecutor") 
	public  void reloadDot( ) { 
		iDot.init();  
	}
	
	/**
	 * 释放充电桩
	 * @param areaid
	 */
	@Async("agvExecutor") 
	public  void releasePower(int dotno) { 
		iPower.unlockPowerByDot(dotno);
	}
	
	@Async("agvExecutor") 
	public  void fullStationMount(int dotno) {
		//填充设备装料情况
		StationBean bean=iStation.getBeanByDot(dotno);
		 iStationMount.fullStationMount(dotno,bean.getTransnum());
	}
	
	@Async("agvExecutor") 
	public  void emptyStationMount(int dotno) {
		//清空设备装料情况
		 iStationMount.clear(dotno);
	}
 
	
	/**
	 * 启用机台
	 * @param dotno
	 */
	@Async("agvExecutor") 
	public void enableStation(int dotno) { 
		iStation.updateStationState(dotno, false);
	}
	
	/**
	 * 禁用机台
	 * @param dotno
	 */
	@Async("agvExecutor") 
	public void disableStation(int dotno) {
		iStation.updateStationState(dotno, true);
	}
	
	
	/**
	 * 启用充电桩
	 * @param dotno
	 */
	@Async("agvExecutor") 
	public void enablePower(int dotno) {
		iPower.updatePowerState(dotno, false);
	}
	
	/**
	 * 禁用充电桩
	 * @param dotno
	 */
	@Async("agvExecutor") 
	public void disablePower(int dotno) {
		iPower.updatePowerState(dotno, true);
	}
	
	
	/**
	 * 释放AGV
	 * @param agvid
	 */
	@Async("agvExecutor") 
	public void releaseAgv(int agvid) {
		iAgv.reset(agvid);
	}
	
	@Async("agvExecutor") 
	public  void resetStation(int dotno) { 
		iStation.resetStation(dotno);
	}
 
	
	@Async("agvExecutor") 
	public  void turnStation(int dotno) { 
		iStation.turnStation(dotno);
	}
 
}
